package util;

import org.codehaus.jackson.map.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by Administrator on 2017/9/13.
 */
public class JsonUtil {
    private static Logger log= LoggerFactory.getLogger(JsonUtil.class);
    private static ObjectMapper mapper = new ObjectMapper();

    public static String obj2Json(Object object){
        try {
            return   mapper.writeValueAsString(object);
        } catch (Exception e) {
            log.error("obj2Json 出错");
            return null;
        }
    }

    public  static  Object json2Obj(String json,Class clazz){
        try {
            return  mapper.readValue(json,clazz);
        } catch (Exception e) {
            log.error("json2Obj 出错 {}",json);
            return null;
        }
    }



}
